

<div class="layui-form" lay-filter="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">问题标题</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="problem" id="problem" value="{{ d.params.problem || '' }}" lay-verify="required" placeholder="请输入问题标题" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">问题回答</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="answer" id="answer" value="{{ d.params.answer || '' }}" lay-verify="required" placeholder="请输入问题回答" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">所属分类</label>
    <div class="layui-input-inline">
        <select name="add_problem_cate_id" id="add_problem_cate_id">
        </select>
    </div>
  </div>
  <script type="text/html" template>
      <input type="hidden" name="id" id="id" value="{{ d.params.id || '' }}">
      <input type="hidden" name="cate_id" id="cate_id" value="{{ d.params.cate_id || '' }}">
  </script>
  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <input type="button" lay-submit lay-filter="LAY-problem-back-submit" value="确认" class="layui-btn">
    </div>
  </div>
</div>

<script>
layui.use(['admin', 'form'], function(){
  var $ = layui.$
  ,form = layui.form;

  $.ajax({
      type:'post',
      url:layui.setter.apiUrl+'/admin/problem/find_problem_cate_list',
      data:'',
      dataType:'json',
      async:true,
      success:function(json){ 
        var cate_id = $('#cate_id').val();
          var option = '<option value="">请选择</option>';  //默认值
          if(json.data.length > 0){
              for(var i=0;i<json.data.length;i++){ 
                  //循环获取返回值，并组装成html代码
                  if(cate_id == json.data[i].id){
                    option +="<option value='"+json.data[i].id+"' selected>"+json.data[i].cate_name+"-"+json.data[i].sub_cate_name+"</option>";
                  }else{
                    option +="<option value='"+json.data[i].id+"'>"+json.data[i].cate_name+"-"+json.data[i].sub_cate_name+"</option>";
                  }
              }
          }
          $("#add_problem_cate_id").html(option);
          form.render('select');
      },
  });
  
});
</script>